package mdt.util;

import java.util.regex.*;

public class StatePreservingMatcher
{
	public StatePreservingMatcher(Matcher _matcher)
	{
		matcher = _matcher;
		hasMatch = false;
	}
	
	private Matcher matcher;
	private boolean hasMatch;
		
	public boolean HasMatch()
	{
		return hasMatch;
	}

	public int start()
	{
		return start(0);
	}

	public int start(int _index)
	{
		if (hasMatch)
			return matcher.start(_index);
		else
			return Integer.MAX_VALUE;
	}
	
	public int end()
	{
		return end(0);
	}
	
	public int end(int _index)
	{
		if (hasMatch)
			return matcher.end(_index);
		else
			return Integer.MAX_VALUE;
	}
	
	public String group()
	{
		return group(0);
	}
	
	public String group(int _index)
	{
		if (hasMatch)
			return matcher.group(_index);
		else
			return null;
	}

	
	public boolean find()
	{
		hasMatch = matcher.find();
		
		return hasMatch;
	}
}
